var http = require('http'),  
superagent = require('superagent'),  
cheerio = require('cheerio'),  
mongoose = require('mongoose'),  
mongourl = 'mongodb://127.0.0.1:27017',  
pageUrls = [],  
pageNum = 100;  
// 8d558e118f32f66f06fe9e5290cf10f0高德key


for(var i = 1; i <= pageNum; i++){  
pageUrls.push('https://www.dianping.com/guangzhou/hotel/p'+i)
}  
mongoose.Promise = global.Promise; 
mongoose.connect(mongourl,{useMongoClient:true});  
var Schema = mongoose.Schema;  
//骨架模版  
var movieSchema = new Schema({  
name: String  
})  
//模型  
var Movie = mongoose.model('Movie', movieSchema);  
//存储数据  

pageUrls.forEach(function(pageUrl){  
superagent.get(pageUrl)  
.end(function(err,page){  
    var $ = cheerio.load(page.text);  
    var quoteUrls = $('li.hotel-block');  
    for(var i = 0;i < quoteUrls.length; i++){  
        var articalUrl =quoteUrls.eq(i).find(".hotel-name-link").text();  
        var moive = new jihai({  
            name : articalUrl  
        })  
        //保存数据库  
        moive.save(function(err) {  
            if (err) {  
                console.log('保存失败')  
                return;  
            }              
        })  
    }  
})  
})  